package com.demo.inpiutkeyboard.util;

import android.app.Activity;
import android.content.Context;
import android.graphics.Rect;
import android.view.View;
import android.view.ViewTreeObserver;

public class KeyboardViewUtils {

    private final static int sDefaultHeight = 570;

    private static String mSaveName = "keyboard_height";
    private static View mRootView;

//    public static int getKeyboardHeight()
//    {
//        Context context = App.getContext();
//        return SPConfig.getPropertyAsInt(context, mSaveName, sDefaultHeight);
//    }

    public static void bindLayout(View view) {
        if (view != null) {
            mRootView = view;
            mRootView.getViewTreeObserver().addOnGlobalLayoutListener(onGlobalLayoutListener);
        }
    }

    private static ViewTreeObserver.OnGlobalLayoutListener onGlobalLayoutListener =
            new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
//            Context context = App.getContext();
//            Activity a = ActivityStack.getForgroundActivity();
//            if (a != null && !a.isFinishing()) {
//                Rect r = new Rect();
//                mRootView.getGlobalVisibleRect(r);
//
//                int viewHeight = r.height();
//                int statusHeight = DisplayUtils.getStatusbarHeightPx(context);　　//获得状态栏高度
//                int titleHeight = DisplayUtils.dp2px(context, 50);　　//标题栏高度
//                int screenHeight = DisplayUtils.getScreenHeightPx(context);　　//屏幕高度
//
//                if (viewHeight + statusHeight + titleHeight + 100 < screenHeight) {
//                    int keyboardHeight = screenHeight - viewHeight - statusHeight - titleHeight;
//                    SPConfig.setProperty(context, mSaveName, keyboardHeight);
//                }
//            }
                }
            };
}